﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AutoMapper;
using Kaiser.Cubic.Models;
using Kaiser.Cubic.Service;
using NewsDetail = Kaiser.Cubic.Models.News.NewsDetail;

namespace Kaiser.Cubic.Areas.China.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /China/Home/
        CubicServiceClient _service = new CubicServiceClient();
        public ActionResult Index()
        {
            var model = new Protal();

            //model.ProductCategories = GetProductCategorys();

            //model.About = GetAboutNews(); ;
            model.About = new NewsDetail();
            model.About.TitleShort = "About Cubic";
            model.About.Content = "testContent";
            model.About.PublishDateTime = DateTime.Now;

            //model.WhyUs = GetWhyUsNews();
            model.WhyUs = new NewsDetail();
            model.WhyUs.TitleShort = "Why Us";
            model.WhyUs.Content = "testWhyUsContent";
            model.WhyUs.PublishDateTime = DateTime.Now;

            
            // CubicServiceClient client = new CubicServiceClient();

            //service.GetProduct()

            return View(model);
        }

        private NewsDetail GetWhyUsNews()
        {
            var model = _service.GetNews(""); //这个可以写到配置文件里面，或者是放在某个文件统一下
            var resultModel = Mapper.Map<Service.NewsDetail, Models.News.NewsDetail>(model);
            return resultModel;
        }

        private NewsDetail GetAboutNews()
        {
            var model = _service.GetNews(""); //这个可以写到配置文件里面，或者是放在某个文件统一下
            var resultModel = Mapper.Map<Service.NewsDetail, Models.News.NewsDetail>(model);
            return resultModel;
        }

        private List<Models.ProductCategory> GetProductCategorys()
        {
            var arr = _service.GetProductCateogrys(null);
            var listResult = Mapper.Map<Service.ProductCategory[], List<Models.ProductCategory>>(arr);

            return listResult;
        }

        public ActionResult About()
        {

            return View();
        }

        public ActionResult Video() 
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }

        public ActionResult ProductTreeMenu()
        {
            return View();
        }
    }
}
